<?php include COMMON_PATH.'/header.html'; ?>
<div class="page page_followstore">
  <div class="weui-body el-scroll">
    <div class="swiper-container swiper-scroll">
      <div class="swiper-wrapper">
        <div class="swiper-slide">
          <ul class="follow-list" id="list">
          </ul>
        </div>
        <div class="load-more-wrapper">
          <img src="/res/mobile/images/loading.gif" class="load-more-pic">
          <p class="load-more-text">下拉加载更多</p>
        </div>
      </div>
    </div>
    <div class="no-data" id="noData" style="display:none;">
      <img src="/res/mobile/images/nostore_pic.png" class="pic">
      <p class="tips">还没有关注的店铺</p>
    </div>
  </div>
</div>
<?php include COMMON_PATH.'/footer.html'; ?>
<script>
  $(function () {
    var isflag = false,
      dataField = {
        page: 1,
        limit: 10
      };



    function getList(field) {
      isflag = true;
      var loading = weui.loading();

      $.ajax({
        url: '/mobile/fund/list',
        dataType: 'json',
        type: 'POST',
        data: field,
        success: function (res) {
          if (res.code == 1) {
            if (res.data.total != 0) {
              var str = '',
                list = res.data.list;

              if (list.length == 0) {
                weui.toast('没有更多记录了', {
                  duration: 2000,
                  className: 'no-more-data'
                });
              }
              str += itemHtml(list);
              $('#list').append(str);
              $('#list').show();
              $('#noData').hide();
              editWidth = $('.edit-delete-btn').width();
              setTimeout(() => {
                myScroll.update();
              }, 100);
            } else {
              $('#list').hide()
              $('#noData').show()
            }
          } else {
            weui.topTips(res.msg)
          }
        },
        complete: function () {
          loading.hide();
          isflag = false;
        }
      })

      function itemHtml(data) {
        var str = '';
        for (var i = 0; i < data.length; i++) {
          str += '<li class="item" data-id="0">';
          str += '<div class="subitem">';
          str += '<div class="avatar-wrapper">';
          str += '<img src="/res/mobile/images/mall/example_pic.png" alt="" class="avatar">';
          str += '</div>';
          str += '<div class="info-wrapper">';
          str += '<h3 class="title">';
          str += '<span class="text">广东上好木业店铺</span>';
          str += '<span class="label-rz">入驻商家</span>';
          str += '</h3>';
          str += '<p class="desc">已上架商品：200条</p>';
          str += '<div class="icon-edit-wrapper">';
          str += '<span class="icon-edit"></span>';
          str += '</div>';
          str += '</div>';
          str += '</div>';
          str += '<div class="edit-delete-btn">取消关注</div>';
          str += '</li>';
        }
        return str;
      }
    }
    getList(dataField)


    //渲染滑动及加载功能
    var myScroll = swiperScroll(function () {
      if (isflag) {
        return false
      }
      dataField.page++;
      getList(dataField);
    })

    //编辑
    function editModule() {
      // 显示删除按钮
      $('#list').on('click', '.icon-edit-wrapper', function (e) {
        e.stopPropagation();
        var li = $(this).closest('li');
        li.hasClass('tranX') ? li.removeClass('tranX') : li.addClass('tranX').siblings().removeClass('tranX');
      })

      $('#list').on('click', '.edit-delete-btn', function (e) {
        var index = $(this).closest('li').data('id');
        weui.confirm('<div class="content tx1">是否删除此足迹？</div>', {
          className: 'confirm-form',
          buttons: [{
            label: '取消',
            type: 'default'
          }, {
            label: '立即删除',
            type: 'primary',
            onClick: function () {
              console.log('删除')
            }
          }]
        });
      })
    }
    editModule();
  })
</script>